<script setup>
import {ElMessage} from "element-plus";
import {onMounted, reactive} from "vue";
import {Select} from "@element-plus/icons-vue";
import {useStore} from "@/stores"
import {postJson} from "@/net";

const store = useStore()
const infoForm = reactive({
  username: '',
  desc: '',
  qq: '',
  wx: '',
  email: '',
  sex: '',
  phone: ''
})

const getDetail = () => {
  postJson('/cat/user/detail', {
    id: store.auth.user.id
  }, (message) => {
    infoForm.desc = message.data.desc
    infoForm.sex = message.data.sex
    infoForm.phone = message.data.phone
    infoForm.email = message.data.email
    infoForm.username = message.data.name
    infoForm.qq = message.data.qq
    infoForm.wx = message.data.wx
  })
}

const updateUser = () => {
  postJson('/cat/user/update', {
    accountId: store.auth.user.id,
    userName: infoForm.username,
    desc: infoForm.desc,
    qq: infoForm.qq,
    wx: infoForm.wx,
    sex: infoForm.sex,
    phone: infoForm.phone
  }, (message) => {
    ElMessage.success(message.message)
  })
}

onMounted(
    getDetail
)



</script>

<template>
  <el-form
      :model="infoForm"
      label-position="top"
      label-width="100px"
      style="max-width: 60vw">
    <el-form-item label="用户名">
      <el-input v-model="infoForm.username"/>
    </el-form-item>
    <el-form-item label="性别">
      <el-radio-group v-model="infoForm.sex" class="ml-4">
        <el-radio :label="1" size="large">男</el-radio>
        <el-radio :label="2" size="large">女</el-radio>
      </el-radio-group>
    </el-form-item>
    <el-form-item label="手机号">
      <el-input v-model="infoForm.phone"/>
    </el-form-item>
    <el-form-item label="qq">
      <el-input v-model="infoForm.qq"/>
    </el-form-item>
    <el-form-item label="微信">
      <el-input v-model="infoForm.wx"/>
    </el-form-item>
    <el-form-item label="邮箱">
      <el-input v-model="infoForm.email" disabled/>
    </el-form-item>
    <el-form-item label="个人简介">
      <el-input v-model="infoForm.desc" type="textarea"/>
    </el-form-item>
  </el-form>
  <el-button :icon="Select" type="success" @click="updateUser">保存个人信息设置</el-button>
</template>

<style scoped>

</style>